package cn.shyouchi.wuguanjia.android.ui.home.security.thread.contact;

import android.content.Intent;
import android.net.Uri;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import cn.shyouchi.wuguanjia.android.R;
import cn.shyouchi.wuguanjia.android.base.BaseActivity;
import cn.shyouchi.wuguanjia.android.widget.GlideCircleTransform;
import cn.shyouchi.wuguanjia.android.widget.TopBar;

public class ContactDetailActivity extends BaseActivity {

    @BindView(R.id.topBar)
    TopBar mTopBar;
    @BindView(R.id.img_header)
    ImageView mImgHeader;
    @BindView(R.id.btn_send_msg)
    RelativeLayout mBtnSendMsg;
    @BindView(R.id.btn_send_call)
    RelativeLayout mBtnSendCall;
    @BindView(R.id.tv_contact_name)
    TextView mTvContactName;
    @BindView(R.id.tv_contact_post)
    TextView mTvContactPost;
    @BindView(R.id.tv_contact_phone)
    TextView mTvContactPhone;

    Contacter mContacter;

    private  final String BASE_URL = "http://118.178.88.132:8000";


    @Override
    public int initContentView() {
        return R.layout.activity_contact_detail;
    }

    @Override
    public void initInjector() {
        mContacter = getIntent().getParcelableExtra("contact");

    }

    @Override
    public void initUiAndListener() {
        ButterKnife.bind(this);
        mTopBar.setTitle(getTitle().toString());
        mTopBar.setLeftIcon(R.mipmap.ic_back);
        setSupportActionBar(mTopBar.getToolbar());

        mTvContactName.setText(mContacter.getName());
        mTvContactPost.setText(mContacter.getDuties());
        mTvContactPhone.setText(mContacter.getPhone());
        bindPersonDetail();

    }

    @Override
    protected boolean isApplyStatusBarTranslucency() {
        return false;
    }

    @Override
    protected boolean isApplyStatusBarColor() {
        return true;
    }


    @OnClick({R.id.btn_send_msg, R.id.btn_send_call})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.btn_send_msg:
                sendMsg();
                break;
            case R.id.btn_send_call:
                sendCall();
                break;
        }
    }


    private void bindPersonDetail() {
        loadHead(BASE_URL + mContacter.getId_card_head_image());
    }

    private void loadHead(String path) {
        Glide.with(mContext)
                .load(path)
                .placeholder(R.mipmap.ic_default_header)
                .transform(new GlideCircleTransform(mContext))
                .into(mImgHeader);
    }


    private void sendMsg() {
        Intent intent = new Intent(Intent.ACTION_SENDTO, Uri.parse("smsto:" + mContacter.getPhone()));
        startActivity(intent);
    }
    private void sendCall() {
        Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + mContacter.getPhone()));
        startActivity(intent);
    }
}
